package com.ctshk.app.user.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SystemBusinessType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.req.UploadReq;
import com.ctshk.rpc.system.service.IFileOSSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;

/**
 * <p>
 * 文件服务 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-26
 */
@Api(value = "文件服务管理", tags = "文件服务管理")
@RestController
@RequestMapping("/file/oss")
public class FileOSSController extends BaseController {

    @DubboReference
    private IFileOSSService fileOSSService;

    @ApiOperation(value = "上传文件", notes = "上传文件")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "上传文件", operDesc = "上传文件")
    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        String fileName = multipartFile.getOriginalFilename();
        return fileOSSService.upload(fileName, multipartFile.getBytes(), SystemBusinessType.IOTC.getCode());
    }

}
